﻿function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
ThemVaoGioHang = function (ID, SL)
{
    var html = '<div class="ms-dlgOverlay" style="display: block; z-index: 1504; width: 1280px; height: 603px;"></div>';
    $("body").append(html);
    if (SL == undefined)
        SL = 1;
    $.ajax({
        url: "CS.aspx",
        data: "ID=" + ID + "&SL=" + SL,
        success: function (response) {
            if (response != false) {
                var retu = response.split(";")
                $(".ThongTinDatHang").html(retu[0]);
                $(".TongTien").html(retu[1] + " VNĐ");
                $(".TongSP").html(retu[2] + " Sản Phẩm");
                window.location = "GioHang.aspx";
            }
            $(".ms-dlgOverlay").remove();
        }
    });
}

ThemVaoYeuThich = function(ID)
{
    $.ajax({
        url: "AjaxLogin.aspx?CheckLogin=1",
        success:function(data)
        {
            if(data=="True")
            {
                $.ajax({
                    url: "CS.aspx?InsertWish=1&IDSP="+ID,
                    success:function(Result)
                    {
                        if(Result)
                        {
                            window.location = "SanPhamYeuThich.aspx";
                        }
                    }
                })
            }
            else
            {
                $("#formDangNhap").dialog("open");
                sessionStorage.YeuThich = 1;
            }
        }
    })
}

DangNhapTaiKhoan = function(UserName,Pass,Remember)
{
    var result = "";
    $.ajax({
        async: false,
        url: "AjaxLogin.aspx",
        data: "id=" + UserName + "&pw=" + Pass + "&rm=" + Remember,
        success: function (msg) {
            result = msg;
        }
    });
    return result;
}

DangXuat = function () {
    var result = "";
    $.ajax({
        async: false,
        url: "AjaxLogin.aspx?DangXuat=1",
        success: function (msg) {
            result = msg;
        }
    });
    return result;
}

Compare = function(ID)
{
    window.location = "http://" + location.host + "/SoSanh.aspx?ID1=" + ID;
}